package com.ibuonline.b2b.admin.dao;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.dimeng.common.base.SuperDAO;
import com.ibuonline.b2b.entity.CmsHotSearchWords;

/**
 * 
 * @author fengyong
 *
 */
public class CmsHotSearchWordsDAO extends SuperDAO<CmsHotSearchWords> {
	
   @SuppressWarnings("unchecked")
public boolean saveOrUpdateCmsHotSearchWords(final List<CmsHotSearchWords> cmsHotSearchWords) {
	   return (Boolean) template.execute(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Transaction transaction = null;
				try {
					transaction = session.beginTransaction();
					for(int i=0; i<cmsHotSearchWords.size(); i++) {
						CmsHotSearchWords chs = cmsHotSearchWords.get(i);
						chs.setLastupdate(new Timestamp(System.currentTimeMillis()));
						session.saveOrUpdate(chs);
					}
					transaction.commit();
					return true;
				} catch (Exception e) {
					if (transaction != null)
						transaction.rollback();
					return false;
				}
			}
		});
	}
	
}
